package com.dream.controller;

import com.dream.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.client.RestTemplate;

@Controller
public class UserController {

    //理解：消费者不应该有service层
    //RestTemplate 供我们直接调用即可
    //(url,实体类: Map,class<T> ResponseType)

    @Autowired
    private RestTemplate restTemplate;

    private static final String REST_URL_PREFIX = "http://localhost:8001";

    @RequestMapping(value = "/consumer/user/get/{id}",method = RequestMethod.GET)
    public User get(@PathVariable("id") int id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/user/get"+id,User.class);
    }
}
